/**
 * Created by chencheng on 2017/8/5.
 */

const Base = require('../base');
const EnumLoginUserInfo = require('../../constants/EnumCookie').EnumLoginUserInfo;
const EnumUserStatus = require('../../constants/EnumUser').EnumUserStatus;
const mkLoginUserCacheKey = require('../../constants/EnumCache').mkLoginUserCacheKey;


/**
 * @apiDefine User 用户管理
 */
module.exports = class extends Base {
    constructor(ctx) {
        super(ctx);
        this.userService = think.service('rbac/user');
        this.helperService = think.service('helper');
    }

    /**
     * @api {GET} /web/rbac/user/get 获取用户列表
     * @apiGroup User
     * @apiVersion 1.0.0
     * @apiDescription 获取用户列表
     *
     * @apiParam (入参) {Number} page
     * @apiParam (入参) {Number} page_size
     * @apiParam (入参) {String} [search_key]  搜索关键字
     * @apiParam (入参) {Number} group_id  部门id
     * @apiParam (入参) {Number} user_status 用户状态 用户状态: 0是禁用; 1是正常;
     *
     * @apiSuccessExample Success-Response:
     {
        "code": 0,
        "msg": "success",
        "data": {
            "count": 1,
            "totalPages": 1,
            "pagesize": 10,
            "currentPage": 1,
            "data": [
                {
                    "user_id": 29,
                    "account_id": 1,
                    "user_name": "chencheng",
                    "user_email": "cheng.chen@tianjishuju.com",
                    "user_phone": "15010003357",
                    "user_password": "e10adc3949ba59abbe56e057f20f883e",
                    "user_status": 1,
                    "created_at": 1510650081491,
                    "updated_at": 1510650081491,
                    "role_id": 1,
                    "group_id": 0,
                    "deleted_at": 1
                }
            ]
        }
    }
     */
    async getAction() {
        const result = await this.userService.getUsers(this.get());

        if (think.isError(result)) {
            // 这里将错误信息返回，或者返回格式化后的错误信息也都可以
            return this.fail(result.message);
        }

        return this.success(result, "success");
    }

}